{extend name="common/base_page" /}

{block name="title"}盘点详情{/block}

{block name="jscssfile"}{/block}

{block name="css"}
<style type="text/css">
body{ background: #ffffff; height:100vh; }
.layui-fluid {
    padding-top: 5px;
}
.layui-table td{
  padding: 9px 5px;
  font-size: 13px;
}
input:disabled { background:#f0efef; }
.layui-form-item { margin-bottom: 0px; }
</style>
{/block}

{block name="body"}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-card-body public-tpl-row1" style="padding: 0px;">
        <form class="layui-form" action="" id="info-form" lay-filter="info-form" onsubmit="return false;">
        <fieldset class="layui-elem-field layui-field-title"><legend>盘点信息</legend></fieldset>
        <div class="layui-form-item">
            <div class="layui-inline"><label class="layui-form-label">盘点日期</label>
                <div class="layui-input-inline" style="width:300px;">
                  <label class="layui-form-label" style="width:280px;text-align: left;">{$info.create_time}</label>
                </div>
            </div>
            <div class="layui-inline"><label class="layui-form-label">盘点备注</label>
                <div class="layui-input-inline" style="width:300px;">
                  <label class="layui-form-label" style="width:280px;text-align: left;">{$info.remarks|default='未填写'}</label>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline" style="width:400px;">
                    <label class="layui-form-label" style="width:400px;text-align: left;">进货盈亏合计：{$info.cost_price|default='0.00'}，零售盈亏合计：{$info.ls_price|default='0.00'}</label>
                </div>
            </div>
        </div>
        <fieldset class="layui-elem-field layui-field-title" style="margin-bottom: 0;"><legend>盘点项目明细</legend></fieldset>
        
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body" style="margin-top:5px;padding:0px 0px;height: 625px;overflow-y: scroll;">
                        <table class="layui-table">
                          <colgroup>
                            <col width="200">
                            <col width="100">
                            <col width="100">
                            <col width="180">
                            <col width="115">
                            <col width="115">
                            <col width="90">
                            <col width="120">
                            <col width="150">
                            <col width="120">
                            <col width="120">
                            <col>
                          </colgroup>
                          <thead>
                            <tr>
                              <th>名称</th>
                              <th style="text-align:center;">规格</th>
                              <th style="text-align:center;">货柜号</th>
                              <th>生产厂商</th>
                              <th style="text-align:center;">进货单价(元)</th>
                              <th style="text-align:center;">零售单价(元)</th>
                              <th style="text-align:center;">单位</th>
                              <th style="text-align:center;">账面数量</th>
                              <th style="text-align:center;">实际数量</th>
                              <th style="text-align:center;">进货盈亏(元)</th>
                              <th style="text-align:center;">零售盈亏(元)</th>
                            </tr>
                          </thead>
                          <tbody id="subListBox">
                          {volist name="table_list" id="vo"}
                          <tr data-drugsid="{$vo.drugs_id}" data-stock="{$vo.stock}" data-costprice="{$vo.cost_price}" data-price="{$vo.price}" id="tr_{$vo.drugs_id}">
                                <td>{$vo.name}</td>
                                <td style="text-align:center;">{$vo.spec}</td>
                                <td style="text-align:center;">{$vo.huogui_no}</td>
                                <td>{$vo.changjia}</td>
                                <td style="text-align:center;">{$vo.cost_price}</td>
                                <td style="text-align:center;">{$vo.price}</td>
                                <td style="text-align:center;">{$vo.unit}</td>
                                <td style="text-align:center;">{$vo.stock}</td>
                                <td style="text-align:center;">{$vo.stock_after}</td>
                                <td style="text-align:center;">{$vo.cost_price_total}</td>
                                <td style="text-align:center;">{$vo.price_total}</td>
                          </tr>
                          {/volist}
                          </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="layui-form-item layui-layout-admin">
              <div class="layui-input-block">
                <div class="layui-footer" style="left: 0;">
                  <button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="info-form-excelbtn">导出</button>
                  {if $info.status elt 0}
                  <button class="layui-btn" lay-submit="" lay-filter="info-form-savebtn1">确认盘点</button>
                  {/if}
                  <a class="layui-btn layui-btn-danger" href="{:url('index/store.pandian/index')}">返回</a>
                </div>
              </div>
            </div>
            <input type="hidden" name="id" value="{$info.id}"/>
        </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
$(function(){
  setTimeout(function(){
    {if $info.status elt 0}
    //盘点确认数据
    layform.on('submit(info-form-savebtn1)', function(data){
      layer.confirm('您确认本条数据正确无误吗？', {
          title:'盘点确认',shade:[0.4,'#000000'],btn: ['确认','取消'] //按钮
      }, function(){
          layer.closeAll();
          _Index.ajax("{:url('index/store.pandian/confim')}",{id:'{$info.id}'},function(d){
              if(d.err == 0)
              {
                  layer.msg(d.msg, {time: 1000},function(){
                    window.location.reload();
                  });
              }else{
                  layer.msg(d.msg, {time: 2000,anim: 4});
              }
          },'请稍候...');
      });
      return false;
    });
    {/if}
    //导出
    layform.on('submit(info-form-excelbtn)', function(data){
        data.field.id = '{$info.id}';
        data.field.all_price = "{$info.ls_price|default='0.00'}";
        data.field.all_cost_price = "{$info.cost_price|default='0.00'}";
        data.field.table_list = getDetailListData(); //列表信息
        if(Object.keys(data.field.table_list).length <= 0)
        {
            layer.msg('暂无盘点明细，无法导出', {time: 2000,anim: 4});
            return false;
        }
        layer.confirm('导出需要一些时间，确定要导出吗？', {
            title:'导出Excel',shade:[0.4,'#000000'],btn: ['确定','取消'],
            btn1:function(){
                layer.closeAll();
                __showLoadingBox('正在导出...');
                var _url = "{:url('index/store.pandian/save_excel')}";
                var _iframe = '<form action="'+_url+'" id="saveExcelForm" method="post">\
                              <input type="hidden" name="pdata" value=\''+JSON.stringify(data.field)+'\'/>\
                            </form>';
                if($("#saveExcelForm").length > 0) $("#saveExcelForm").remove();
                $('body').append(_iframe);
                $("#saveExcelForm").submit();
                setTimeout(function(){ __hideLoadingBox(); }, 1000);
            }
        });
    });
    layform.render();
  },50);
});
//获取列表--数据
function getDetailListData()
{
    var _list = {}, t = 0;
    if(parseInt($('#subListBox tr').length) <= 0) return _list;
    $('#subListBox tr').each(function(i,v){
        var _idKeyName = parseInt($(this).data('drugsid'));
        var _num = parseInt($(this).find('td').eq(8).text()); //实际盘点数量
        _list[t] = {};
        _list[t]['drugs_id'] = _idKeyName;
        _list[t]['name'] = $(this).find('td').eq(0).text();
        _list[t]['spec'] = $(this).find('td').eq(1).text();
        _list[t]['huogui_no'] = $(this).find('td').eq(2).text();
        _list[t]['changjia'] = $(this).find('td').eq(3).text();
        _list[t]['cost_price'] = parseFloat($(this).find('td').eq(4).text());
        _list[t]['price'] = parseFloat($(this).find('td').eq(5).text());
        _list[t]['unit'] = $(this).find('td').eq(6).text();
        _list[t]['stock'] = $(this).find('td').eq(7).text();
        _list[t]['stock_after'] = _num;
        _list[t]['cost_price_total'] = parseFloat($(this).find('td').eq(9).text());
        _list[t]['price_total'] = parseFloat($(this).find('td').eq(10).text());
        t++;
    });
    return _list;
}
</script>
{/block}